{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "d791bc8a",
   "metadata": {},
   "source": [
    "<a href=\"https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/retrievers/you_retriever.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d9075b09-3916-49b0-b565-b0a0091b5872",
   "metadata": {},
   "source": [
    "# You.com Retriever\n",
    "\n",
    "This notebook walks you through how to setup a Retriever that can fetch from You.com"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b5ac8d10",
   "metadata": {},
   "outputs": [],
   "source": [
    "%pip install llama-index-retrievers-you"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1fb3b393-1171-4481-b75f-b7626ef7b0b2",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.retrievers.you import YouRetriever"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a38b87b3-c94e-4311-8335-86c6b0f32463",
   "metadata": {},
   "outputs": [],
   "source": [
    "you_api_key = \"\" or os.environ[\"YOU_API_KEY\"]\n",
    "\n",
    "retriever = YouRetriever(api_key=you_api_key)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bbfc0fe3-7c64-4d5d-8190-f80e31d35b4c",
   "metadata": {},
   "outputs": [],
   "source": [
    "retrieved_results = retriever.retrieve(\"national parks in the US\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3142a3af-d9a0-4fc1-a6a4-f42eb11a9099",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(retrieved_results[0].get_content())\n",
    "\n",
    "from llama_index.core.response.notebook_utils import display_source_node\n",
    "\n",
    "# for n in retrieved_results:\n",
    "#     display_source_node(n)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6d4f7dc5-bfcd-4f04-8475-e2a6125d70bd",
   "metadata": {},
   "source": [
    "## Use in Query Engine"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a4c879f7-7554-4822-94df-cfe008a03a68",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.core.query_engine import RetrieverQueryEngine\n",
    "\n",
    "query_engine = RetrieverQueryEngine.from_args(\n",
    "    retriever,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "471102ba-aed8-435d-9ddc-de51644aa886",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The United States has 63 national parks, which are protected areas operated by the National Park Service. These parks are designated for their natural beauty, unique geological features, diverse ecosystems, and recreational opportunities. They are typically larger and more popular destinations compared to other units of the National Park System. National monuments, on the other hand, are also protected for their historical or archaeological significance. Some national parks are paired with national preserves, which have different levels of protection but are administered together. The national parks in the United States cover a total area of approximately 52.4 million acres.\n"
     ]
    }
   ],
   "source": [
    "response = query_engine.query(\"Tell me about national parks in the US\")\n",
    "print(str(response))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "llama_index_v2",
   "language": "python",
   "name": "llama_index_v2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
